﻿using System;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace GUITree
{
	// Token: 0x020004B6 RID: 1206
	[AddComponentMenu("GUITree/Preferred Size Fitter", 1001)]
	[ExecuteInEditMode]
	[RequireComponent(typeof(RectTransform))]
	public class PreferredSizeFitter : UIBehaviour, ITreeLayoutElement, ILayoutSelfController, ILayoutElement, ILayoutController
	{
		// Token: 0x06001E2A RID: 7722 RVA: 0x000BEE1C File Offset: 0x000BD01C
		protected PreferredSizeFitter()
		{
		}

		// Token: 0x06001E2B RID: 7723 RVA: 0x000BEE3C File Offset: 0x000BD03C
		public virtual void CalculateLayoutInputHorizontal()
		{
		}

		// Token: 0x06001E2C RID: 7724 RVA: 0x000BEE40 File Offset: 0x000BD040
		public virtual void CalculateLayoutInputVertical()
		{
		}

		// Token: 0x1700033C RID: 828
		// (get) Token: 0x06001E2D RID: 7725 RVA: 0x000BEE44 File Offset: 0x000BD044
		public virtual float minWidth
		{
			get
			{
				return this.m_PreferredWidth;
			}
		}

		// Token: 0x1700033D RID: 829
		// (get) Token: 0x06001E2E RID: 7726 RVA: 0x000BEE4C File Offset: 0x000BD04C
		public virtual float minHeight
		{
			get
			{
				return this.m_PreferredHeight;
			}
		}

		// Token: 0x1700033E RID: 830
		// (get) Token: 0x06001E2F RID: 7727 RVA: 0x000BEE54 File Offset: 0x000BD054
		// (set) Token: 0x06001E30 RID: 7728 RVA: 0x000BEE5C File Offset: 0x000BD05C
		public virtual float preferredWidth
		{
			get
			{
				return this.m_PreferredWidth;
			}
			set
			{
				if (SetPropertyUtility.SetStruct<float>(ref this.m_PreferredWidth, value))
				{
					this.SetDirty();
				}
			}
		}

		// Token: 0x1700033F RID: 831
		// (get) Token: 0x06001E31 RID: 7729 RVA: 0x000BEE78 File Offset: 0x000BD078
		// (set) Token: 0x06001E32 RID: 7730 RVA: 0x000BEE80 File Offset: 0x000BD080
		public virtual float preferredHeight
		{
			get
			{
				return this.m_PreferredHeight;
			}
			set
			{
				if (SetPropertyUtility.SetStruct<float>(ref this.m_PreferredHeight, value))
				{
					this.SetDirty();
				}
			}
		}

		// Token: 0x17000340 RID: 832
		// (get) Token: 0x06001E33 RID: 7731 RVA: 0x000BEE9C File Offset: 0x000BD09C
		public virtual float flexibleWidth
		{
			get
			{
				return this.m_PreferredWidth;
			}
		}

		// Token: 0x17000341 RID: 833
		// (get) Token: 0x06001E34 RID: 7732 RVA: 0x000BEEA4 File Offset: 0x000BD0A4
		public virtual float flexibleHeight
		{
			get
			{
				return this.m_PreferredHeight;
			}
		}

		// Token: 0x17000342 RID: 834
		// (get) Token: 0x06001E35 RID: 7733 RVA: 0x000BEEAC File Offset: 0x000BD0AC
		public virtual int layoutPriority
		{
			get
			{
				return int.MaxValue;
			}
		}

		// Token: 0x17000343 RID: 835
		// (get) Token: 0x06001E36 RID: 7734 RVA: 0x000BEEB4 File Offset: 0x000BD0B4
		private RectTransform rectTransform
		{
			get
			{
				if (this.m_Rect == null)
				{
					this.m_Rect = base.GetComponent<RectTransform>();
				}
				return this.m_Rect;
			}
		}

		// Token: 0x06001E37 RID: 7735 RVA: 0x000BEEDC File Offset: 0x000BD0DC
		protected override void OnEnable()
		{
			base.OnEnable();
			this.SetDirty();
		}

		// Token: 0x06001E38 RID: 7736 RVA: 0x000BEEEC File Offset: 0x000BD0EC
		protected override void OnDisable()
		{
			this.m_Tracker.Clear();
			if (this.rectTransform != null)
			{
				LayoutRebuilder.MarkLayoutForRebuild(this.rectTransform);
			}
			base.OnDisable();
		}

		// Token: 0x06001E39 RID: 7737 RVA: 0x000BEF1C File Offset: 0x000BD11C
		protected override void OnRectTransformDimensionsChange()
		{
			this.SetDirty();
		}

		// Token: 0x06001E3A RID: 7738 RVA: 0x000BEF24 File Offset: 0x000BD124
		private void HandleSelfFittingAlongAxis(int axis)
		{
			this.m_Tracker.Add(this, this.rectTransform, (axis != 0) ? DrivenTransformProperties.SizeDeltaY : DrivenTransformProperties.SizeDeltaX);
			this.rectTransform.SetSizeWithCurrentAnchors((RectTransform.Axis)axis, LayoutUtility.GetPreferredSize(this, axis));
		}

		// Token: 0x06001E3B RID: 7739 RVA: 0x000BEF60 File Offset: 0x000BD160
		public virtual void SetLayoutHorizontal()
		{
			this.m_Tracker.Clear();
			this.HandleSelfFittingAlongAxis(0);
		}

		// Token: 0x06001E3C RID: 7740 RVA: 0x000BEF74 File Offset: 0x000BD174
		public virtual void SetLayoutVertical()
		{
			this.HandleSelfFittingAlongAxis(1);
		}

		// Token: 0x06001E3D RID: 7741 RVA: 0x000BEF80 File Offset: 0x000BD180
		protected void SetDirty()
		{
			if (!this.IsActive())
			{
				return;
			}
			if (this.rectTransform != null)
			{
				LayoutRebuilder.MarkLayoutForRebuild(this.rectTransform);
			}
		}

		// Token: 0x0400208E RID: 8334
		[SerializeField]
		private float m_PreferredWidth = -1f;

		// Token: 0x0400208F RID: 8335
		[SerializeField]
		private float m_PreferredHeight = -1f;

		// Token: 0x04002090 RID: 8336
		[NonSerialized]
		private RectTransform m_Rect;

		// Token: 0x04002091 RID: 8337
		private DrivenRectTransformTracker m_Tracker;
	}
}
